home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / egs.lha / EGS / EGS_Devels / Examples / EGS_Requester / requester.c < prev    next >
C/C++ Source or Header  |  1993-02-17  |  6KB  |  238 lines

  1. /*
  2. **  Author: Markus van Kempen
  3. **  Date  : 18. Dezember 1992
  4. **          09 Jan 1993 mvk
  5. **
  6. **  This example shows how to work with EGS_REQUESTER.
  7. **
  8. **  It is an example for non modal requester.
  9. **
  10. **  You can request a lot of messages without waiting for
  11. **
  12. **  response from the user to the requester.
  13. **
  14. **  For example in the file requester: if the user makes some
  15. **
  16. **  mistakes (like to select a file as a device) then you can put up
  17. **
  18. **  a requester for him.
  19. **
  20. **
  21. **
  22. **  (c) by VIONA-Development 1992/93
  23. **
  24. */
  25.  
  26.  
  27. /*
  28. ** Init-Routines
  29. */
  30.  
  31. #include "global.h"
  32.  
  33. /*
  34. **
  35. */
  36.  
  37. ER_FileRequestPtr    freq;
  38. ER_SimpleRequestPtr  sreq,sreq1,sreq2,sreq3;
  39. EI_EIntuiMsgPtr      msg;
  40. ER_ReqContextPtr     mycon;
  41. ER_RequestPtr        req;
  42.  
  43. struct     MsgPort  *port;
  44. BOOL                 done;
  45. int                  i;
  46.  
  47.  
  48. void myError(char *string,int ende)
  49. {
  50.  
  51.   if ( string != NULL)
  52.           printf("%s\n",string);
  53.  
  54.   if ( ErrorReq != NULL )
  55.      ER_DeleteRequest(&(ErrorReq->Req));
  56.  
  57.   CloseLibraries(OpenStruct);
  58.  
  59.   if (ende)
  60.        exit(0);
  61.  
  62. }
  63.  
  64. /*
  65. **
  66. ** Open the Libraries
  67. **
  68. */
  69.  
  70. BOOL InitLibraries(struct OpenStructTyp *OS)
  71. {
  72.  struct OpenStructTyp *p = &OS[0];
  73.  
  74.  while (p->Base != NULL)
  75.  {
  76.    if ((*(p->Base) = (ULONG)OpenLibrary(p->Name,p->Version)) == NULL)
  77.        {
  78.            printf(" Can't open %s version %d",p->Name, p->Version);
  79.            return FALSE;
  80.        }
  81.        else
  82.        {  p ++; }
  83.  }
  84.    return TRUE;
  85. }
  86. /**/
  87.  
  88. /*
  89. **
  90. ** Close Libs
  91. **
  92. */
  93.  
  94. void CloseLibraries(struct OpenStructTyp *OS)
  95. {
  96.  struct OpenStructTyp *p = &OS[0];
  97.  
  98.  while (*(p->Base) != NULL && p->Name != NULL)
  99.  {
  100.         CloseLibrary((void *)(*(p->Base)));
  101.         *(p->Base) = NULL;
  102.         p++;
  103.  }
  104. }
  105.  
  106.  
  107. main()
  108. {
  109.  
  110.         if ( InitLibraries(OpenStruct) == FALSE)
  111.              myError("Can't OpenLibrary",10);
  112.  
  113.         port = CreatePort(NULL,0);
  114.  
  115.         if ( port == NULL )
  116.             myError("Can't create port",10);
  117.  
  118.         mycon = ER_CreateReqContext();
  119.  
  120.         if (mycon != NULL)
  121.         {
  122.                 /*
  123.                 ** Create the context for all
  124.                 */
  125.  
  126.                 freq=ER_CreateFileReq(mycon);
  127.  
  128.                 sreq=ER_CreateSimpleRequest(mycon,
  129.            " ! ERROR ! | You selected a filename | as a device !",
  130.                    " YES | MAY BE | NO ");
  131.  
  132.                 sreq1=ER_CreateSimpleRequest(mycon,
  133.            " ! ERROR ! | The selected path | doesn't exist !",
  134.                    " YES | MAY BE | NO ");
  135.  
  136.                 sreq2=ER_CreateSimpleRequest(mycon,
  137.            " ! ERROR ! | You selected a wrong | devicename !",
  138.                    " YES | MAY BE | NO ");
  139.  
  140.                 sreq3=ER_CreateSimpleRequest(mycon,
  141.                    " This is a demo | for non modal  | requesters !",
  142.                    " YES ");
  143.  
  144.                 /*
  145.         ** Init Port in requester struct for use of
  146.                 ** non modal requesters.
  147.                 **
  148.         ** Without a port the OpenRequest will create
  149.         ** a own port, so that any requester has an own
  150.                 ** MsgPort (modal).
  151.                 **
  152.                 **
  153.                 */
  154.  
  155.                 freq->Req.Port=port;
  156.                 sreq->Req.Port=port;
  157.                 sreq1->Req.Port=port;
  158.                 sreq2->Req.Port=port;
  159.                 sreq3->Req.Port=port;
  160.  
  161.                 if (sreq1 != NULL && sreq2 != NULL && sreq3 != NULL)
  162.                 if (freq != NULL && sreq != NULL)
  163.                 {
  164.  
  165.                          freq->Req.Title="Titel1";
  166.                          sreq->Req.Title="Titel2";
  167.                         sreq1->Req.Title="Titel3";
  168.                         sreq2->Req.Title="Titel4";
  169.                         sreq3->Req.Title="Titel5";
  170.  
  171.                         done=FALSE;
  172.  
  173.                         if ( ER_OpenRequest((ER_RequestPtr)freq,NULL)  &&
  174.                              ER_OpenRequest((ER_RequestPtr)sreq,NULL)  &&
  175.                              ER_OpenRequest((ER_RequestPtr)sreq2,NULL) &&
  176.                              ER_OpenRequest((ER_RequestPtr)sreq1,NULL) &&
  177.                              ER_OpenRequest((ER_RequestPtr)sreq3,NULL)
  178.                              )
  179.  
  180.                         {
  181.  
  182.                         do{
  183.                              WaitPort(port);
  184.  
  185.                              msg=(EI_EIntuiMsgPtr)GetMsg((struct MsgPort *)port);
  186.  
  187.                              if (msg != NULL)
  188.                              {
  189.  
  190.                                 /*
  191.                                 ** Find the Requester for the msg
  192.                                 **
  193.                                 ** if req == NULL the msg
  194.                                 ** is not from a EGS Requester
  195.                                 **
  196.                                 */
  197.  
  198.                                 req = ER_FindRequest(mycon,msg);
  199.  
  200.                                 if (req != NULL)
  201.                                 {
  202.                                     /*
  203.                                     ** Handle the msg !
  204.                     ** For example close requester
  205.                                     */
  206.  
  207.                                     ER_IterateRequest(req,msg);
  208.  
  209.    //                             printf("Selected gadget%d\n",sreq->Selected);
  210.  
  211.                                 }
  212.  
  213.                              }
  214.  
  215.                              ReplyMsg((struct Message *)msg);
  216.  
  217.                            }while(freq->Req.RWindow != NULL);
  218.  
  219.                          printf("Name = %s \n\n",freq->Name);
  220.  
  221.                         }
  222.  
  223.                 }
  224.         }
  225.  
  226.       if( con != NULL )
  227.              ER_DeleteReqContext(mycon);
  228.  
  229.       DeletePort(port);
  230.  
  231.       myError(NULL,10);
  232.  
  233. }
  234.  
  235. /* END */
  236.  
  237.  
  238.